<?php
/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: dzf_base_view.php 4159 2014-09-09 03:01:36Z laoguozhang $
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

class dzf_base_view extends dzf_base_class
{
	protected $_data = array();
	protected $_path = './template/default';
	public $ext_name = 'phtml';

	public function render($view, $data = array(), $return = false) {
		$viewname = $this->_path.'/'.$view.'.'.$this->ext_name;

		if(!file_exists($viewname)) {
			throw new Exception('Template '. $view. ' not found');
		} else {
			extract(array_merge($this->_data, $data));
			//TODO render return view content
			$ret = require $viewname;
		}
	}

	public function path($path = NULL) {
		if(isset($path)) {
			$realpath = realpath($path);
			if($realpath) {
				$this->_path = $realpath;
			}
		} else {
			return $this->_path;
		}
		return $this;
	}

	public function assign($name, $value = NULL) {
		$this->_data[$name] = $value;
	}

	public function sub($name) {
		if(!empty($name)) {
			return $this->_path.'/'.$name.'.'.$this->ext_name;
		} else {
			return false;
		}
	}

}